import React from 'react'
import { Form, Input, Checkbox, Button } from 'antd'
import './index.css';
import { replace, useNavigate } from 'react-router-dom';


function Login() {

  const navitate = useNavigate();

  const onFinish = (values) => {
    let json = JSON.stringify(values);
    localStorage.setItem('token', json);
    navitate('/', {
      replace: false
    })
  }

  return (
    <div className='main-wrap'>
      <Form
        className='form'
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ minWidth: 600 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item
          label="用户名"
          name="username"
          rules={[{ required: true, message: '请输入用户名' }]}
        >
          <Input />
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"
          rules={[{ required: true, message: '请输入密码' }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item label={null}>
          <Button type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  )
}

export default Login;